package com.project.service;

import com.project.dao.SchoolManagerInfoMapper;
import com.project.entity.SchoolManagerInfo;
import com.project.service.base.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author: TateBrown
 * @date: 2018/5/26 14:59
 * @param:
 * @return:
 */
@Transactional(rollbackFor = Exception.class)
@Service
public class SchoolManagerInfoServiceImpl extends BaseService implements SchoolManagerInfoService {
    @Autowired
    private  SchoolManagerInfoMapper schoolManagerInfoMapper ;

    /**
     * author: WheelChen
     * date: 2017/7/25
     * function: 根据userId查找对应字段
     *
     * @param userId
     * @return
     */
    @Override
    public SchoolManagerInfo findByUserId(Integer userId) {
        return schoolManagerInfoMapper.selectByUserId(userId);
    }

    /**
     * author: WheelChen
     * date: 2017/7/31
     * function: 添加一个学院管理员
     *
     * @param schoolManagerInfo
     * @return
     */
    @Override
    public int addOne(SchoolManagerInfo schoolManagerInfo) {
        return schoolManagerInfoMapper.insertSelective(schoolManagerInfo);
    }

    /**
     * author: WheelChen
     * date: 2017/9/18
     * function: 根据学院id查找单个学院
     *
     * @param schoolId
     * @return
     */
    @Override
    public SchoolManagerInfo findOneBySchoolId(Integer schoolId) {
        return schoolManagerInfoMapper.selectOneBySchoolId(schoolId);
    }

    /**
     * author: WheelChen
     * date: 2017/10/18
     * function: 根据学院管理员信息表中的学院id是否已存在判断该学院是否已有学院管理员
     *
     * @param schoolId
     * @return false-不存在 true-存在
     */
    @Override
    public boolean checkSchoolManagerIsExist(Integer schoolId) {
        return schoolManagerInfoMapper.checkSchoolManagerIsExist(schoolId) != 0;
    }

    /**
     * author: WheelChen
     * date: 2017/10/30
     * function: 根据学院id删除学院管理员信息表
     *
     * @param schoolId 学院id
     * @return
     */
    @Override
    public int removeOneBySchoolId(Integer schoolId) {
        return schoolManagerInfoMapper.deleteOneBySchoolId(schoolId);
    }

    /**
     * author: WheelChen
     * date: 2017/10/30
     * function: 根据用户id删除学院管理员信息表
     *
     * @param userId 用户id
     * @return
     */
    @Override
    public int removeOneByUserId(Integer userId) {
        return schoolManagerInfoMapper.deleteOneByUserId(userId);
    }
}
